package com.gegong.imr.client.bean;

import com.gegong.vmware.workstation.VMInformation;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.virtualbox_5_2.IMachine;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class VmStatus {
    private String mac;
    private String state;


    public static VmStatus fromVbox(IMachine machine) {
        VmStatus clientStatus = new VmStatus();
        switch (machine.getState()) {
            case Running:
                clientStatus.setState("1");
                break;
            case PoweredOff:
                clientStatus.setState("0");
                break;
            case Paused:
                clientStatus.setState("2");
                break;
        }

        clientStatus.setMac(machine.getNetworkAdapter(0L).getMACAddress());
        return clientStatus;
    }


    public static VmStatus fromVmware(VMInformation vmInformation) {
        VmStatus clientStatus = new VmStatus();
        switch (vmInformation.getPowerState().getState()) {
            case poweredOn:
                clientStatus.setState("1");
                break;
            case poweredOff:
                clientStatus.setState("0");
                break;
            case paused:
                clientStatus.setState("2");
                break;
        }
        String macAddress = vmInformation.getDevices().getDevices().get(0).getMacAddress();
        clientStatus.setMac(macAddress.replaceAll(":", ""));
        return clientStatus;
    }
}
